package com.ly.cloud.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.ly.cloud.common.mybatisplus.plugins.PageInfo;
import com.ly.cloud.dto.ProfessionalInfoDto;
import com.ly.cloud.service.ProfessionalInfoService;
import com.ly.cloud.vo.*;
import com.ly.cloud.web.utils.WebResponse;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Description: 专业Controller
 * @Author: pengshiqng
 * @Date: Create in 2018/12/13
 */

@RestController
@RequestMapping("/profeInfo")
@Api("专业Controller")
public class ProfessionalInfoController {

    @Autowired
    private ProfessionalInfoService professionalInfoService ;


    /**
     * 分页+条件查询
     */
    @RequestMapping(value = "/queryPageList", method = RequestMethod.POST)
    public WebResponse<PageInfo<ProfessionalInfoVo>> queryPageList( @RequestParam("pageNum") int pageNum, @RequestParam("pageSize") int pageSize, @RequestBody ProfessionalInfoDto dto){
        Page<ProfessionalInfoVo> page = professionalInfoService.selectPage(new Page<ProfessionalInfoVo>(pageNum, pageSize), dto);
        return new WebResponse<PageInfo<ProfessionalInfoVo>>().success(PageInfo.toPageInfo(page));
    }


    /**
     * 树形结构 查询所有教学部门
     * 如果传参数parentDwh，这查询改专业下的子专业，否则，查询最顶级的专业
     */
    @RequestMapping(value = "/tree", method = RequestMethod.GET)
    public WebResponse<List<DwSelectVO>> tree(@RequestParam(required = false, value = "parentZyh") String parentZyh){
        List<DwSelectVO> list = professionalInfoService.tree(parentZyh);
        return new WebResponse<List<DwSelectVO>>().success(list) ;
    }

    /**
     * 根据id删除
     */
    @RequestMapping(value = "/deleteById/{id}", method = RequestMethod.POST)
    public WebResponse<Integer> deleteById(@PathVariable("id") String id){
        int result = professionalInfoService.deleteById(id) ;
        return new WebResponse<Integer>().success(result);
    }

    /**
     * 根据id批量删除
     */
    @RequestMapping(value = "/deleteByIds", method = RequestMethod.POST)
    public WebResponse<Integer> deleteByIds(@RequestBody List<String> ids){
        int result = professionalInfoService.deleteByIds(ids) ;
        return new WebResponse<Integer>().success(result);
    }

    /**
     * 插入
     */
    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    public WebResponse<Boolean> insert(@RequestHeader(required=false,value = "loginUserName") String loginUserName,@RequestBody ProfessionalInfoDto dto){
        professionalInfoService.insert(loginUserName ,dto);
        return new WebResponse<Boolean>().success(true) ;
    }

    /**
     * 更新
     */
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public WebResponse<Boolean> update(@RequestHeader(required=false,value = "loginUserName") String loginUserName,@RequestBody ProfessionalInfoDto dto){
        professionalInfoService.uodateById(loginUserName, dto);
        return new WebResponse<Boolean>().success(true) ;
    }
    
    /**
     * 查询专业下拉列表
     * 根据院系代码过滤专业
     * @author caihuihai 2018-12-20
     */
    @RequestMapping(value = "/findProListByDwh/{dwh}", method = RequestMethod.GET)
    public WebResponse<List<ProfessVo>> findProListByDwh(@PathVariable("dwh") String dwh){
        List<ProfessVo> list = professionalInfoService.findProListByDwh(dwh);
        return new WebResponse<List<ProfessVo>>().success(list) ;
    }
    
    /**
     * 查询全部专业,下拉列表
     * @author luhuacong 2018-12-28
     */
    @RequestMapping(value = "/selectAllPro", method = RequestMethod.GET)
    public WebResponse<List<ProfessionalInfoVo>> selectAllPro(){
    	List<ProfessionalInfoVo> list = professionalInfoService.selectAllPro();
        return new WebResponse<List<ProfessionalInfoVo>>().success(list) ;
    }


    /**
     * 查询全部专业,下拉列表
     * @author luhuacong 2018-12-28
     */
    @RequestMapping(value = "/pyccSelect", method = RequestMethod.GET)
    public WebResponse<List<SelectVo>> pyccSelect(){
        List<SelectVo> list = professionalInfoService.pyccSelect();
        return new WebResponse<List<SelectVo>>().success(list) ;
    }

    /**
    * @Description: 新增的时候 查询专业号是否存在
    * @author: pengshiqing
    * @date: 2019/1/4
    */
    @RequestMapping(value = "/checkedZyh", method = RequestMethod.GET)
    public WebResponse<Boolean> checkedZyh(@RequestParam String zyh){
        return new WebResponse<Boolean>().success(professionalInfoService.checkedZyh(zyh)) ;
    }


    /**
     * @Description: 通过专业号查询专业信息
     * @author: pengshiqing
     * @date: 2019/1/4
     */
    @RequestMapping(value = "/findProfessByZyh", method = RequestMethod.GET)
    public WebResponse<ProfessionalInfoVo> findProfessByZyh(@RequestParam String zyh){
        return new WebResponse<ProfessionalInfoVo>().success(professionalInfoService.findProfessByZyh(zyh)) ;
    }

    /**
    * @Description: 学科门类 下拉
    * @author: pengshiqing
    * @date: 2019/1/7
    */
    @RequestMapping(value = "/findXkmlSelect", method = RequestMethod.GET)
    public WebResponse<List<XkmlSelectVo>> findXkmlSelect(){
        return new WebResponse<List<XkmlSelectVo>>().success(professionalInfoService.findXkmlSelect()) ;
    }

    /**
     * @Description: 大学科 下拉
     * @author: pengshiqing
     * @date: 2019/1/7
     */
    @RequestMapping(value = "/findDxkSelect", method = RequestMethod.GET)
    public WebResponse<List<DxkSelectVo>> findDxkSelect(){
        return new WebResponse<List<DxkSelectVo>>().success(professionalInfoService.findDxkSelect()) ;
    }

    /**
     * @Description: 一级学科 下拉
     * @author: pengshiqing
     * @date: 2019/1/7
     */
    @RequestMapping(value = "/findYjxkSelect", method = RequestMethod.GET)
    public WebResponse<List<YjxkSelectVo>> findYjxkSelect(){
        return new WebResponse<List<YjxkSelectVo>>().success(professionalInfoService.findYjxkSelect()) ;
    }

    /**
     * @Description: 专业类别 下拉
     * @author: pengshiqing
     * @date: 2019/1/7
     */
    @RequestMapping(value = "/findZylbSelect", method = RequestMethod.GET)
    public WebResponse<List<ZylbSelectVo>> findZylbSelect(){
        return new WebResponse<List<ZylbSelectVo>>().success(professionalInfoService.findZylbSelect()) ;
    }



}
